import { Controller, Get, Query, ParseIntPipe } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { StatisticsService } from './statistics.service';
import { VisitStatsResponseDto } from './dto/visit-stats.dto';
import { StatsOverviewResponseDto } from './dto/stats.overview.dto';

@ApiTags('网站统计')
@Controller('statistics')
export class StatisticsController {
  constructor(private readonly statisticsService: StatisticsService) {}

  @ApiOperation({ summary: '获取网站访问统计' })
  @ApiResponse({
    status: 200,
    description: '返回网站访问统计数据',
    type: VisitStatsResponseDto,
  })
  @Get('visit')
  async getVisitStats(
    @Query('days', new ParseIntPipe({ optional: true })) days = 7,
  ) {
    const data = await this.statisticsService.getVisitStats(days);
    return data;
  }

  @ApiOperation({ summary: '获取总访问量统计' })
  @Get('total')
  async getTotalStats() {
    const data = await this.statisticsService.getTotalStats();
    return data;
  }

  @ApiOperation({ summary: '获取统计概览数据' })
  @ApiResponse({
    status: 200,
    description: '返回今日访问统计概览',
    type: StatsOverviewResponseDto,
  })
  @Get('overview')
  async getStatsOverview() {
    const data = await this.statisticsService.getStatsOverview();
    return data;
  }
}
